<?php
/**
 * 后台模块管理，用于添加城市、专业等原始数据类
 * edit by gemj
 * 2011－03－23
 */

class Admin_Page_Ajax extends Admin_Page_Abstract
{
    public function validate(ME_Request $input, ME_Response $output)
    {
        $module_list = array();
        $module_arr = Libs_Admin_Module::getModuleList(array());
        if(!empty($module_arr) && is_array($module_arr)){
            foreach ($module_arr as $module){
                $id = $module['id'];
                $name = $module['name'];
                $module_list[$id] = $name;
            }
        }
        $output->module_list = $module_list;

        return true;
    }

    public function doDefault(ME_Request $input, ME_Response $output)
    {
        $catogoryadd = $input->post("catogoryadd");
        if(!empty ($catogoryadd)){
            $name = $input->post("name");
            $classid = $input->post("classid");
            $subclassid = $input->post("subclassid");
            $module_type = $input->post("module_type");
        }
        $list = Libs_Admin_Category::getCategoryList();
        $output->list = $list;

        $output->setTemplate("CategoryManage");
    }


    #获取类别
    public function doGetClass(ME_Request $input, ME_Response $output)
    {
        $module_type = $input->get("module_type");
        $list = Libs_Admin_Category::getCategoryList(array("module_type"=>$module_type,"type"=>1));
        $newlist = array();
        if(!empty($list) && is_array($list)){
            foreach ($list as $key=>$val){
                $classid = $val['classid'];
                $name = $val['name'];
                $newlist[$key]['id'] = $classid;
                $newlist[$key]['name'] = $name;
            }
        }
        
        echo json_encode($newlist);
        exit;
    }

    #获取子类
    public function doGetSubClass(ME_Request $input, ME_Response $output)
    {
        $module_type = $input->get("module_type");
        $classid = $input->get("classid");
        $list = Libs_Admin_Category::getCategoryList(array("module_type"=>$module_type,"classid"=>$classid,"type"=>2));
        $newlist = array();
        
        if(!empty($list) && is_array($list)){
            foreach ($list as $key=>$val){
                $subclassid = $val['subclassid'];
                $name = $val['name'];
                $newlist[$key]['id'] = $subclassid;
                $newlist[$key]['name'] = $name;
            }
        }

        echo json_encode($newlist);
        exit;
    }
}
